<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
			<el-form-item label="推送状态" prop="pushStatus">
				<el-select v-model="queryParams.pushStatus" placeholder="请选择推送状态" clearable>
					<el-option v-for="dict in push_status" :key="dict.value" :label="dict.label" :value="dict.value" />
				</el-select>
			</el-form-item>
			<el-form-item label="告警时间" style="width: 308px;">
				<el-date-picker v-model="dateRange" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
				 start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
				<el-button icon="Refresh" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<!--      <el-col :span="1.5">-->
			<!--        <el-button-->
			<!--          type="primary"-->
			<!--          plain-->
			<!--          icon="Plus"-->
			<!--          @click="handleAdd"-->
			<!--          v-hasPermi="['archive:ArchiveBoxIllegalRecords:add']"-->
			<!--        >新增</el-button>-->
			<!--      </el-col>-->
			<!--      <el-col :span="1.5">-->
			<!--        <el-button-->
			<!--          type="success"-->
			<!--          plain-->
			<!--          icon="Edit"-->
			<!--          :disabled="single"-->
			<!--          @click="handleUpdate"-->
			<!--          v-hasPermi="['archive:ArchiveBoxIllegalRecords:edit']"-->
			<!--        >修改</el-button>-->
			<!--      </el-col>-->
			<!--      <el-col :span="1.5">-->
			<!--        <el-button-->
			<!--          type="danger"-->
			<!--          plain-->
			<!--          icon="Delete"-->
			<!--          :disabled="multiple"-->
			<!--          @click="handleDelete"-->
			<!--          v-hasPermi="['archive:ArchiveBoxIllegalRecords:remove']"-->
			<!--        >删除</el-button>-->
			<!--      </el-col>-->
			<el-col :span="1.5">
				<el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['archive:ArchiveBoxIllegalRecords:export']">导出</el-button>
			</el-col>
			<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="ArchiveBoxIllegalRecordsList" @selection-change="handleSelectionChange">
			<el-table-column label="序号" align='center' width="100">
				<template #default="scope">
					{{ scope.$index+1 }}
				</template>
			</el-table-column>
			<!--      <el-table-column type="selection" width="55" align="center" />-->
			<!--      <el-table-column label="序号" align="center" prop="id" />-->
			<el-table-column label="档案室编号" align="center" prop="roomNo" />
			<el-table-column label="告警时间" align="center" prop="alarmTime">
				<template #default="scope">
					<span>{{ parseTime(scope.row.alarmTime) }}</span>
				</template>
			</el-table-column>
			<el-table-column label="推送状态" align="center" prop="pushStatus">
				<template #default="scope">
					<dict-tag :options="push_status" :value="scope.row.pushStatus" />
				</template>
			</el-table-column>
			<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<!--        <template #default="scope">-->
				<!--          <el-button-->
				<!--            type="text"-->
				<!--            icon="Edit"-->
				<!--            @click="handleUpdate(scope.row)"-->
				<!--            v-hasPermi="['archive:ArchiveBoxIllegalRecords:edit']"-->
				<!--          >修改</el-button>-->
				<!--          <el-button-->
				<!--            type="text"-->
				<!--            icon="Delete"-->
				<!--            @click="handleDelete(scope.row)"-->
				<!--            v-hasPermi="['archive:ArchiveBoxIllegalRecords:remove']"-->
				<!--          >删除</el-button>-->
				<!--        </template>-->
				<template #default="scope">
					<el-button type="text" icon="View" @click="handleView(scope.row, scope.index)" v-hasPermi="['archive:ArchiveBoxIllegalRecords:query']">详细</el-button>
				</template>
			</el-table-column>
		</el-table>

		<pagination v-show="total>0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
		 @pagination="getList" />

		<!-- 添加或修改非法携带盒记录对话框 -->
		<!--    <el-dialog :title="title" v-model="open" width="500px" append-to-body>-->
		<!--      <el-form ref="ArchiveBoxIllegalRecordsRef" :model="form" :rules="rules" label-width="120px">-->
		<!--        <el-form-item label="供电单位编号" prop="orgNo">-->
		<!--          <el-input v-model="form.orgNo" placeholder="请输入供电单位编号" />-->
		<!--        </el-form-item>-->
		<!--        <el-form-item label="接口编号" prop="serviceCode">-->
		<!--          <el-input v-model="form.serviceCode" placeholder="请输入接口编号" />-->
		<!--        </el-form-item>-->
		<!--        <el-form-item label="档案室编号" prop="roomNo">-->
		<!--          <el-input v-model="form.roomNo" placeholder="请输入档案室编号" />-->
		<!--        </el-form-item>-->
		<!--        <el-form-item label="告警时间" prop="alarmTime">-->
		<!--          <el-input v-model="form.alarmTime" placeholder="请输入告警时间" />-->
		<!--          <el-date-picker clearable-->
		<!--                          v-model="form.alarmTime"-->
		<!--                          type="datetime"-->
		<!--                          value-format="YYYY-MM-DD HH:mm:ss"-->
		<!--                          placeholder="请选择告警时间">-->
		<!--          </el-date-picker>-->
		<!--        </el-form-item>-->
		<!--      </el-form>-->
		<!--      <template #footer>-->
		<!--        <div class="dialog-footer">-->
		<!--          <el-button type="primary" @click="submitForm">确 定</el-button>-->
		<!--          <el-button @click="cancel">取 消</el-button>-->
		<!--        </div>-->
		<!--      </template>-->
		<!--    </el-dialog>-->

		<!-- 详细 -->
		<el-dialog title="非法携带盒记录详细" v-model="openscan" width="80%" append-to-body>
			<el-form ref="ArchiveBoxIllegalRecordsRef" :model="form" label-width="130px">
				<el-row>
					<el-col :span="8">
						<el-form-item label="档案室编号：">
							<el-input v-model="form.roomNo" disabled="disabled" />
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="告警时间：">
							<el-input v-model="form.alarmTime" disabled="disabled" />
						</el-form-item>
					</el-col>
				</el-row>
				<!--        <el-divider content-position="center">档案盒记录详细数据</el-divider>-->
				<el-table :data="archiveBoxList" style="min-height: 550px;border:1px solid #dcdfe6;max-height: 550px;"
				 :highlight-current-row="true" height="550" border>
					<el-table-column label="序号" align='center'>
						<template #default="scope">
							{{ scope.$index+1 }}
						</template>
					</el-table-column>
					<el-table-column label="档案盒号" prop="boxNo" align="center" />
					<el-table-column label="档案区编号" align="center" prop="areaNo" />
					<el-table-column label="档案柜编号" align="center" prop="cabinetNo" />
					<el-table-column label="档案盒条码" prop="boxRfid" align="center" />
					<el-table-column label="库位号" prop="houseLocationNo" align="center">
					</el-table-column>
				</el-table>
			</el-form>
			<template #footer>
				<div class="dialog-footer">
					<el-button @click="openscan = false">关 闭</el-button>
				</div>
			</template>
		</el-dialog>
	</div>
</template>

<script setup name="ArchiveBoxIllegalRecords">
	import {
		listArchiveBoxIllegalRecords,
		getArchiveBoxIllegalRecords,
		delArchiveBoxIllegalRecords,
		addArchiveBoxIllegalRecords,
		updateArchiveBoxIllegalRecords,
		getFFBoxInoutRecordList
	} from "@/api/archive/ArchiveBoxIllegalRecords";
	import {
		getCurrentInstance,
		reactive,
		ref,
		toRefs
	} from "vue";
	const archiveBoxList = ref([]);
	const {
		proxy
	} = getCurrentInstance();

	const ArchiveBoxIllegalRecordsList = ref([]);
	const open = ref(false);
	const loading = ref(true);
	const showSearch = ref(true);
	const ids = ref([]);
	const single = ref(true);
	const multiple = ref(true);
	const total = ref(0);
	const title = ref("");
	const dateRange = ref([]);
	const data = reactive({
		form: {},
		queryParams: {
			pageNum: 1,
			pageSize: 10,
			orgNo: null,
			serviceCode: null,
			roomNo: null,
			alarmTime: null,
			status: null,
			pushStatus: null
		},
		rules: {}
	});
	const {
		push_status
	} = proxy.useDict('push_status');
	const openscan = ref(false);
	const {
		queryParams,
		form,
		rules
	} = toRefs(data);

	/** 查询非法携带盒记录列表 */
	function getList() {
		loading.value = true;
		// listArchiveBoxIllegalRecords(queryParams.value).then(response => {
		listArchiveBoxIllegalRecords(proxy.addDateRange(queryParams.value, dateRange.value)).then(response => {
			ArchiveBoxIllegalRecordsList.value = response.rows;
			total.value = response.total;
			loading.value = false;
		});
	}

	// 取消按钮
	function cancel() {
		open.value = false;
		reset();
	}

	// 表单重置
	function reset() {
		form.value = {
			id: null,
			orgNo: null,
			serviceCode: null,
			roomNo: null,
			alarmTime: null,
			status: "0",
			pushStatus: "0"
		};
		proxy.resetForm("ArchiveBoxIllegalRecordsRef");
	}

	/** 搜索按钮操作 */
	function handleQuery() {
		queryParams.value.pageNum = 1;
		getList();
	}

	/** 重置按钮操作 */
	function resetQuery() {
		dateRange.value = [];
		proxy.resetForm("queryRef");
		handleQuery();
	}

	// 多选框选中数据
	function handleSelectionChange(selection) {
		ids.value = selection.map(item => item.id);
		single.value = selection.length != 1;
		multiple.value = !selection.length;
	}

	/** 新增按钮操作 */
	function handleAdd() {
		reset();
		open.value = true;
		title.value = "添加非法携带盒记录";
	}

	/** 修改按钮操作 */
	function handleUpdate(row) {
		reset();
		const id = row.id || ids.value
		getArchiveBoxIllegalRecords(id).then(response => {
			form.value = response.data;
			open.value = true;
			title.value = "修改非法携带盒记录";
		});
	}

	/** 提交按钮 */
	function submitForm() {
		proxy.$refs["ArchiveBoxIllegalRecordsRef"].validate(valid => {
			if (valid) {
				if (form.value.id != null) {
					updateArchiveBoxIllegalRecords(form.value).then(response => {
						proxy.$modal.msgSuccess("修改成功");
						open.value = false;
						getList();
					});
				} else {
					addArchiveBoxIllegalRecords(form.value).then(response => {
						proxy.$modal.msgSuccess("新增成功");
						open.value = false;
						getList();
					});
				}
			}
		});
	}

	/** 删除按钮操作 */
	function handleDelete(row) {
		const ids = row.id || ids.value;
		proxy.$modal.confirm('是否确认删除非法携带盒记录编号为"' + ids + '"的数据项？').then(function() {
			return delArchiveBoxIllegalRecords(ids);
		}).then(() => {
			getList();
			proxy.$modal.msgSuccess("删除成功");
		}).catch(() => {});
	}

	/** 导出按钮操作 */
	function handleExport() {
		proxy.download('archive/ArchiveBoxIllegalRecords/export', {
			...queryParams.value
		}, `非法携带盒记录_${new Date().getTime()}.xlsx`)
	}

	function handleView(row) {
		openscan.value = true;
		form.value = row;
		getFFBoxInoutRecordList(row.id).then(response => {
			if (response.code == "200") {
				archiveBoxList.value = response.data;
			} else {
				proxy.$modal.msgError(response.msg);
			}
		});
	}
	getList();
</script>
